<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <title>未确认退货单</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>

<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">

    <section class="content-header">
        <h1>未确认退货单</h1>
        <ol class="breadcrumb">
             <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
             <li class="active"><a href="#">交易</a></li>
             <li class="active"><a href="#"><spring:message code="message.lable.TuiHuoGuanLi"/></a></li>
             <li class="active"><a href="#">未确认退货单</a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class="input">
                	<div class="textalign1"><spring:message code="message.lable.yiLiaoJiGouMingCheng"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                         <input type="text" class="textinput" id="hospName" name="hospName"  placeholder="<spring:message code="message.lable.yiLiaoJiGouMingCheng"/>/<spring:message code="message.listForm.pinYinMa"/>" />
                    </div>
                	<div class="textalign1"><spring:message code="message.listForm.TuiHuoDanHao"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                         <input type="text" class="textinput" id="retCode" name="retCode"  placeholder="<spring:message code="message.listForm.TuiHuoDanHao"/>" />
                    </div>
                    
                  
                    <div class="textalign1"><spring:message code="message.listForm.TuiHuoRiQi"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput"> 
                       <table style="width:100%">
                           <tr>
                               <td style="width:50%">
                                   <input id="startDate" name="startDate" type="text" class="textinput" placeholder="yyyy-MM-dd" 
                                       data-date-fmt="yyyy-MM-dd" onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'endDate\')}'})" />
                               </td>
                               <td>&nbsp;-&nbsp;</td>
                               <td style="width:50%">
                                   <input id="endDate" name="endDate" type="text" class="textinput"  placeholder="yyyy-MM-dd" 
                                   data-date-fmt="yyyy-MM-dd" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'startDate\')}'})" />
                               </td>
                           </tr>
                       </table>
                    </div>
                    <div class="textalign1" >
                        <button id="selectDicCompType" type="button" class="btn btn-success btn-sm" onclick="search()">
                            <spring:message code="message.button.seachSpacing"/>
                        </button>
                    </div>
                      <div class="textalign1" style="display: none;"><spring:message code="message.lable.yiLiaoJiGouBianMa"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput" style="display: none;">
                         <input type="text" class="textinput" id="hospCode" name="hospCode"  placeholder="<spring:message code="message.lable.yiLiaoJiGouBianMa"/>" />
                    </div>
                </div>
              <%--  < div class="input" style="margin-top:-5px">
                    <div class="textalign1"><spring:message code="message.listForm.TuiHuoRiQi"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput"> 
                       <table style="width:100%">
                           <tr>
                               <td style="width:50%">
                                   <input id="startDate" name="startDate" type="text" class="textinput" placeholder="yyyy-MM-dd" 
                                       data-date-fmt="yyyy-MM-dd" onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'endDate\')}'})" />
                               </td>
                               <td>&nbsp;-&nbsp;</td>
                               <td style="width:50%">
                                   <input id="endDate" name="endDate" type="text" class="textinput"  placeholder="yyyy-MM-dd" 
                                   data-date-fmt="yyyy-MM-dd" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'startDate\')}'})" />
                               </td>
                           </tr>
                       </table>
                    </div>
                    <div class="textalign" >
                        <button id="selectDicCompType" type="button" class="btn btn-success btn-sm" onclick="search()">
                            <spring:message code="message.button.seachSpacing"/>
                        </button>
                    </div>
                </div> --%>
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
        <div class=" box box-warning bottongroup">
             <label class="btn btn-primary btn-sm" onclick="agreeReturnConfirm(2)"><spring:message code="message.listForm.TongYi"/></label>
             <label class="btn btn-danger btn-sm" onclick="rejectReturnConfirm(3)"><spring:message code="message.listForm.JuJue"/></label>
        </div>
        
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
	    function showOrderDetail(retCode) {
	        $.HN.window.open({
	            "id" : "orderDetail",
	            "title" : "退货明细",
	            "url" : "${ctx}/returnConfirm/toReturnDetail.html?retCode=" + retCode
	        });
	    }
	    
	    function orderDetailLink(retCode, text) {
	        return "<a href='javascript:showOrderDetail(\"" + retCode + "\")' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -100px 0px' class='opIcon' title='明细'></a>";
	    }
    
        $(function () {
        	//绑定回车
            $('#retCode,#hospCode,#hospName,#startDate,#endDate').bind('keydown', function(event) {
                if (event.keyCode == "13") {
                    $('#selectDicCompType').click();
                }
            }); 
            $("#hospName").focus();//加载页面光标在第一个查询框内
        	
            $("#gridlist").jqGrid({
                url: "getReturnConfirm.html",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                //shrinkToFit: false,
             //   height: 270,
                colNames: [
                    '<spring:message code="message.jqGrid.cz"/>',
                    '状态',
                    '拒绝理由',
                    '<spring:message code="message.listForm.TuiHuoDanBianHao"/>',
                    '<spring:message code="message.lable.yiLiaoJiGouBianMa"/>',
                    '<spring:message code="message.lable.yiLiaoJiGouMingCheng"/>',
                    '退货数量',
                    '<spring:message code="message.listForm.ZongJinE"/>',
                    '<spring:message code="message.listForm.TuiHuoShiJian"/>',
                    '<spring:message code="message.listForm.TuiHuoRen"/>'
                ],
                colModel: [
	               { name: 'operate', width: 60,align:"center",sortable:false, 
	                   formatter:function(val, opts, row) {
	                       return orderDetailLink(row.retCode);
	                   }
	               },
	               { name: 'returnStatus', width: 80,align:"center",sortable:false },
	               { name: 'confirmRemark', width: 180,align:"center",sortable:false},
	               { name: 'retCode', width: 180, align: "center" ,sortable:false },
	               { name: 'hospCode',hidden:true, width: 120, align: "center" ,sortable:false },
	               { name: 'hospName', width: 180, align:"left", sortable:false},
	               { name: 'detailCount', width: 80, align: "right",sortable:false },
	               { name: 'detailAmount', width: 80, align: "right", sortable:false,
	            	   formatter:function(val, opts, row){
                           return formatAmount(val);
                       }
	               },
	               { name: 'retDatetime', width: 160, align: "center", sortable:false },
	               { name: 'retUser', width: 180, align: "left", sortable:false }
                ],
                rowNum: 20,
                rowList: [10, 20,50,100],
                rownumbers: true,
                multiselect: true,
                pager: "#gridpage",
                viewrecords: true,
                gridComplete: function(){
                	  //序号列宽度自适应（参数为jqgridID）
                      autoRNWidth("gridlist");
                      //数据只有一条时默认选中（参数为jqgridID）
                      selectByOneData("gridlist");
                      var ids = jQuery("#gridlist").jqGrid('getDataIDs');
                  	  for(var i=0;i < ids.length;i++){
                			var id = ids[i];
                			a = "<input class='gridText confirmRemark' type='text'  inputTag='"+id+"' maxlength='512' id='confirmRemark_" + id + "' />";
                    		jQuery("#gridlist").jqGrid('setRowData',ids[i],{confirmRemark:a});
                	  }
                      
                  	   $('.confirmRemark').keyup(function(event){
                  		 var num =$(this).attr("inputTag");
                       	changeSelectChecked("#gridlist",num,$(this).val(),event);
                       }); 
                      
                      
                },
                caption: "未确认退货单列表",
                jsonReader: {
                    repeatitems: false,
                    id: "ids"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
			$("#gridlist").jqGrid("setGridHeight", create());
        });
        
        /* 查询 */
        function search(page) {
            var retCode = $.trim($("#retCode").val());
            var hospCode = $.trim($("#hospCode").val());
            var hospName = $.trim($("#hospName").val());
            var startDate = $.trim($("#startDate").val());
            var endDate = $.trim($("#endDate").val());
            $("#gridlist").jqGrid("clearGridData");
                $("#gridlist").jqGrid('setGridParam',{  
                mtype: "POST",
                datatype:'json',
                postData:{
                	"retCode":retCode, 
                    "hospCode":hospCode,
                    "hospName":hospName,
                    "startDate":startDate,
                    "endDate":endDate
                },
                page : (page || 1)
            }).trigger("reloadGrid"); //重新载入  
        }
        
        /* 同意 */
        function agreeReturnConfirm(status) {
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.alert("请选择同意的退货单！", "warn");
                return;
            }
            var list = [];
            var data ="";
            for (var i=0; i<rowIds.length; i++) {
            	var rowId = rowIds[i];
                var rowData = $("#gridlist").jqGrid("getRowData", rowId);
                list.push({"retCode":rowData.retCode});
                if(i<3){
             	   data += "<br/>" + rowData.hospName + "-" + rowData.retCode ;    
             	   if(i==2){
             		   data += "<br/>...";
             	   }
              }
            }
            $.HN.message.confirm("确认同意以下退货吗？"+data, 
            		"<spring:message code='message.HN.alert.type' />", 
            		"<spring:message code='message.lable.OKYES' />").on(function(bool) {
                if (bool) {
                	 $.post("agreeReturnConfirm.html", {
                         "array" : json.jsonToString(list)
                     }, function(result) {
                         if (result.success) {
                             var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
                             search(curpage);
                             $.alert("同意成功！", "success");
                         } else {
                             $.alert(result.msg || "同意失败！", "error");
                         }
                     }, "json"); 
                }
            });
        }
        
        
        /* 拒绝 */
        function rejectReturnConfirm(status) {
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.alert("请选择拒绝的退货单！", "warn");
                return;
            }
            var list = [];
            var data = "";
            for (var i=0; i<rowIds.length; i++) {
                rowId = rowIds[i];
                var confirmRemark = $.trim($("#confirmRemark_" + rowId).val());
                $("#confirmRemark_" + rowId).val(confirmRemark);
                
                if (confirmRemark == null || confirmRemark == "") {
                    $.alert("请输入拒绝理由！", "warn");
                    $("#confirmRemark_" + rowId).focus();
                    return;
                }else if(confirmRemark.length > 512){
                	$.alert("拒绝理由最多512个字！", "warn");
                	return;
                }
                var rowData = $("#gridlist").jqGrid("getRowData", rowId);
                list.push({"retCode":rowData.retCode, "confirmRemark":confirmRemark});
                var rowData = $("#gridlist").jqGrid("getRowData", rowId);
                if(i<3){
             	   data += "<br/>" + rowData.hospName + "-" + rowData.retCode ;    
             	   if(i==2){
             		   data += "<br/>...";
             	   }
              }
            }
            
            $.HN.message.confirm("确认拒绝以下退货吗？"+data, 
            		"<spring:message code="message.HN.alert.type"/>", 
            		"<spring:message code="message.lable.OKYES"/>").on(function(bool) {
                if (bool) {
                	$.post("rejectReturnConfirm.html", {
                        "array" : json.jsonToString(list)
                    }, function(result) {
                        if (result.success) {
                            var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
                            search(curpage);
                            $.alert("拒绝成功！", "success");
                        } else {
                            $.alert(result.msg || "拒绝失败！", "error");
                        }
                    }, "json"); 
                }
            });
        }
        
    </script>
</body>
</html>